#!/bin/bash
sql_script="/home/aqdms/CARBLog/sys_resources/upgrade_scripts/sql_index.txt"
ulog="/home/aqdms/CARBLogger_upgrade_log"
checkfile="/home/aqdms/CARBLog/sys_resources/upgrade_scripts/.update_index"
cdate=`date`

if [ ! -e "$checkfile" ]; then
	test=`mysql -u root --password=carblogger carblogger -e "show index from cl_ingests;" | grep IND | wc -l`
	if [ "$test" -gt "0" ]; then
		if (mysql -u root --password=carblogger carblogger < $sql_script); then
			echo "$cdate : UPDATE SQL INDEX" >> $ulog
			echo "ran $sql_script against database" >> $ulog
			touch "$checkfile"
		else
			echo "cdate : UPDATE SQL INDEX " >> $ulog
			echo "FAILURE TO UPDATE DATABASE"
		fi
	fi
fi